home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 1_0-2 / D2R_FOLD / D2R_OPEN.C < prev    next >
C/C++ Source or Header  |  1986-11-06  |  1KB  |  45 lines

  1. #include "D2R globals.h"
  2.  
  3.  
  4. open()
  5. {
  6.     /* IO packet    */
  7.     Str255        filename;
  8.     int            vrefnum,
  9.                 refnum,
  10.                 errcode;
  11.     int            currVol;
  12.     OSErr        err;
  13.     
  14.     if(GetFile(NULL,filename,&vrefnum))
  15.     {
  16.         /* Empty buffer */
  17.         if (GetHandleSize(RezH) != NULL)
  18.             DisposHandle(RezH);
  19.         /* GetVol(NULL,&currVol);
  20.         SetVol(NULL,vrefnum); */
  21.         if ((err = FSOpen(filename,vrefnum,&refnum)) != noErr)
  22.             ErrorAlert("\pSorry - can't open that file!");
  23.         /* SetVol(NULL,currVol); */
  24.         /* get size of the file */
  25.         GetEOF(refnum, &count);
  26.         /* allocate buffer */
  27.         RezH = (Handle) NewHandle(count);
  28.         if (RezH == NULL)
  29.         {
  30.             /* not enough room: close channel */
  31.             myError(OutOfMemErr);
  32.             /* and exit */
  33.             return(false);
  34.         }
  35.         HLock(RezH); /* NEVER dereference a floating handle!! */
  36.         if ((errcode = FSRead(refnum,&count,*RezH)) != noErr)
  37.             ErrorAlert("\pSorry - can't read that file!");
  38.         HUnlock(RezH);
  39.         err = FSClose(refnum);
  40.         EnableItem(mymenu[file_menu],igetinfo);
  41.         EnableItem(mymenu[file_menu],iwrite);
  42.         strcpy(RezName,filename);
  43.     }
  44. }
  45.